package com.example.yywebflux01;

import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

import java.math.BigDecimal;
import java.time.Duration;
import java.util.Random;

@Service
public class StockPriceService {

    public Flux<StockPrice> getStockPrices(String symbol) {
        Random random = new Random();
        return Flux.interval(Duration.ofSeconds(1)).take(5)
                .map(i -> new StockPrice(symbol, BigDecimal.valueOf(random.nextDouble() * 100), System.currentTimeMillis()));
    }
}
